/* Initial beliefs and rules */
/* BELIEFS */


/* RULES */



/* initial DESIRES */
!search_enemy_corral.


/* INTENTIONS (PLANS AND ACTIONS) */
+!find_pos : true
	<-  .wait("+pos(_,_,_)").
		
	
+!search_enemy_corral: not pos(_,_,_) 
	<-	!find_pos;
		!search_enemy_corral.
		

+!search_enemy_corral: pos(_,_,_) & not cell(_,_,E) 
	<- 	!search_enemy_corral.
		
	
+!search_enemy_corral: pos(_,_,_) & cell(_,_,E) 
	<-	if(E \== enemycorral)
		{
			!search_enemy_corral;
			.print("ninguem achou curraaaal!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
		}
		else
		{
			.print("indo para o curral inimigo!");
			!goto_enemy_corral;
		}
		.

+!goto_enemy_corral: pos(X,Y,_) & cell(Ex,Ey,_) & not fence(Fx,Fy,_)
	<-	.print("goto corral!");
		br.poli.ecomp.sma.massim.action.FindPos(X,Y,CX,CY,NewX,NewY);
     	br.poli.ecomp.sma.massim.action.FindDirection(X,Y,NewX,NewY,Direction);
     	moveTo(Direction);
     	.wait("+pos(_,_,_)");
     	!goto_enemy_corral.
     	
+!goto_enemy_corral: pos(X,Y,_) & cell(Ex,Ey,_) & fence(Fx,Fy,_) & corral(Cx,Cy,C1x,C2y)
	
	<- br.poli.ecomp.sma.massim.action.CercaPertenceCurral(Cx,Cy,C1x,C2y,Ex,Ey,Fx,Fy,Resp);
	if( Resp == true ){
	.print("CERCA TA NO CURRAL!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
	+target(Fx,Fy);
	!move
	}
	.
+!move : pos(X,Y,_) & target(Fx,Fy) & Fx \== X & Fy \== Y
	<- 	.print("CONTINUE ANDANDO ATE CHEGAR NA CERCA");
  	 	br.poli.ecomp.sma.massim.action.FindPos(X,Y,Fx,Fy,NewX,NewY);
     	br.poli.ecomp.sma.massim.action.FindDirection(X,Y,NewX,NewY,Direction);
     	.print(Direction);
     	moveTo(Direction);
     	!move.
     	
+!move : pos(X,Y,_) & target(Fx,Fy) 
	<- 	.print("CHEGUEI NA CERCAAAAAAAAA!!!!!!!!!!!!!!!!!!").